package tests;

import global.*;
import heap.InvalidSlotNumberException;
import heap.Tuple;
import iterator.FileScan;
import iterator.FldSpec;
import iterator.RelSpec;

import java.io.*;

public class ImportTests {

	public static void main (String argv[]) throws InvalidSlotNumberException, Exception 
	{
		Schema ts = null;
		try {
			if ((ts = Batch.OldInsert("/Users/ebeerman/Desktop/sampledata", "test2")) != null)
			{
				System.out.println("Successful");
			}
			else
			{
				System.err.println("Failed");
			}
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		if (ts!=null)
		{
		    // create an iterator by open a file scan
		    FldSpec[] projlist = new FldSpec[2];
		    RelSpec rel = new RelSpec(RelSpec.outer); 
		    projlist[0] = new FldSpec(rel, 1);
		    projlist[1] = new FldSpec(rel, 2);
		    
		    FileScan fscan = null;
		    
		    try {
		      fscan = new FileScan("test", ts.attrType, ts.attrSize, 
		    		  (short) ts.attrType.length, 2, projlist, null);
				Tuple t;
				int cnt = 0;
				while ((t = fscan.get_next()) != null)
				{
					cnt++;
					if (cnt==1)
					{
						System.out.format("%f ", t.getFloFld(1));
						System.out.println(t.get100DVectFld(2).toString());
					}
				}
				System.out.format("Read %d tuples.", cnt);
				fscan.close();
		    }
		    catch (Exception e) {
		      e.printStackTrace();
		    }
		}
	}
}
